package zcw.com.lib_leet_code;

/**
 * Created by 朱城委 on 2021/7/19.<br><br>
 *
 * 汉明距离
 */
public class Topic461 {

    public static void main(String[] args) {
        Topic461 instance = new Topic461();

        System.out.println(instance.hammingDistance(1, 4));
        System.out.println(instance.hammingDistance(3, 1));
    }

    public int hammingDistance(int x, int y) {
        int temp = x ^ y;

        int result = 0;
        while (temp != 0) {
            result++;
            temp = temp & (temp - 1);
        }

        return result;
    }
}
